import { createStore } from 'vuex'
import user from './modules/user';
import store from './modules/store'
import commodity from './modules/commodity'
import order from './modules/order';
import address from './modules/address';
import activity from './modules/activity';
import createPersistedState from "vuex-persistedstate"

export default createStore({
    state: {
        // 管理员（商店）面板侧边栏的展开和折叠
        isCollapse: false,

        // MallMain的scrollbar
        MallMainScrollBarRef: null,

        // 管理员界面侧边栏
        adminMenu: [
            {
                index: "/admin/home",
                label: "首页",
                icon: ['fas', 'house']
            },
            {
                index: "/admin/user",
                label: "用户管理",
                icon: ['fas', 'user']
            },
            {
                index: '/admin/webshop-account',
                label: "商城账户",
                icon: ['fas', 'circle-dollar-to-slot']
            },
            {
                index: '/admin/category',
                label: '商品类别',
                icon: ['fas', 'tags']
            },
            {
                label: "店铺管理",
                name: 'admin-store',
                icon: ['fas', 'shop'],
                children: [
                    {
                        index: "/admin/store",
                        label: "所有店铺",
                        icon: ['fas', 'store'],
                    },
                    {
                        index: "/admin/store/open-request",
                        label: "开店申请",
                        icon: ['fas', 'key'],
                    },
                    {
                        index: "/admin/store/delete-request",
                        label: "关店申请",
                        icon: ['fas', 'store-slash'],
                    },
                ],
            },
            {
                label: "商品管理",
                name: 'admin-commodity',
                icon: ['fas', 'cube'],
                children: [
                    {
                        index: "/admin/commodity",
                        label: "所有商品",
                        icon: ['fas', 'gifts']
                    },
                    {
                        index: "/admin/commodity/launch-request",
                        label: "上架申请",
                        icon: ['fas', 'upload']
                    },
                    {
                        index: "/admin/commodity/modify-request",
                        label: "修改申请",
                        icon: ['fas', 'pen-to-square']
                    },
                ],
            },
            {
                label: "补贴活动",
                name: 'admin-activity',
                icon: ['fas', 'bell'],
                children: [
                    {
                        index: "/admin/activity",
                        label: "所有活动",
                        icon: ['fas', 'thumbtack']
                    },
                    {
                        index: "/admin/activity/participate-request",
                        label: "参与申请",
                        icon: ['fas', 'handshake']
                    },
                ],
            },
        ],

        // 商户管理商店界面侧边栏
        sellerMenu: [
            {
                index: "/store-manage/home",
                label: "首页",
                icon: ['fas', 'house']
            },
            {
                label: "商店账户",
                index: "/store-manage/account",
                icon: ['fas', 'circle-dollar-to-slot']
            },
            {
                label: "发货信息",
                index: "/store-manage/send-info",
                icon: ['fas', 'truck-arrow-right']
            },
            {
                label: "退款申请",
                index: "/store-manage/revoke-request",
                icon: ['fas', 'hand-holding-dollar']
            },
            {
                label: "商城活动",
                name: 'manage-activity',
                icon: ['fas', 'bell'],
                children: [
                    {
                        index: '/store-manage/activity',
                        label: "有效活动",
                        icon: ['fas', 'thumbtack']
                    },
                    {
                        index: "/store-manage/activity-request",
                        label: "活动申请记录",
                        icon: ['fas', 'paper-plane']
                    }
                ]
            },
            {
                label: "商品管理",
                name: "manage-commodity",
                icon: ['fas', 'cube'],
                children: [
                    {
                        index: "/store-manage/commodity",
                        label: "商品列表",
                        icon: ['fas', 'gifts']
                    },
                    {
                        index: "/store-manage/launch-commodity",
                        label: "申请上架商品",
                        icon: ['fas', 'upload']
                    },
                    {
                        index: "/store-manage/launch-request",
                        label: "上架申请记录",
                        icon: ['fas', 'clock-rotate-left']
                    },
                    {
                        index: "/store-manage/modify-request",
                        label: "修改申请记录",
                        icon: ['fas', 'pen-to-square']
                    }
                ]
            },
        ],

        // 商户用户中心侧边栏
        sellerUserCenterMenu: [
            {
                index: "/mall/user_center/userinfo",
                label: "个人信息",
                icon: ['fas', 'user'],
            },
            {
                index: "/mall/user_center/address",
                label: "收货地址",
                icon: ['fas', 'map-location'],
            },
            {
                index: "/mall/user_center/revoke",
                label: "退款申请",
                icon: ['fas', 'handshake-slash']
            },
            {
                label: "我的订单",
                name: 'my-orders',
                icon: ['fas', 'clipboard-list'],
                children: [
                    {
                        index: "/mall/user_center/order/all",
                        label: "所有订单",
                        icon: ['fas', 'receipt'],
                    },
                    {
                        index: "/mall/user_center/order/pay",
                        label: "待付款",
                        icon: ['fas', 'credit-card'],
                    },
                    {
                        index: "/mall/user_center/order/send",
                        label: "待发货",
                        icon: ['fas', 'box'],
                    },
                    {
                        index: "/mall/user_center/order/receive",
                        label: "待收货",
                        icon: ['fas', 'truck-fast'],
                    },
                    {
                        index: "/mall/user_center/order/finish",
                        label: "已完成",
                        icon: ['fas', 'comment-dots'],
                    },
                    {
                        index: "/mall/user_center/order/revoke",
                        label: "已撤销",
                        icon: ['fas', 'reply'],
                    },
                    {
                        index: "/mall/user_center/order/refund",
                        label: "已退款",
                        icon: ['fas', 'hand-holding-dollar'],
                    }
                ],
            },
            {
                label: '我的商店',
                name: 'my-stores',
                icon: ['fas', 'shop'],
                children: [
                    {
                        index: "/mall/user_center/stores",
                        label: "商店列表",
                        icon: ['fas', 'store'],
                    },
                    {
                        index: "/mall/user_center/open_store",
                        label: "申请开店",
                        icon: ['fas', 'key'],
                    },
                    {
                        index: "/mall/user_center/open_request",
                        label: "开店申请记录",
                        icon: ['fas', 'list'],
                    },
                    {
                        index: "/mall/user_center/delete_request",
                        label: "关店申请记录",
                        icon: ['fas', 'store-slash'],
                    },
                ]
            },
            {
                label: "我的账户",
                name: 'my-account',
                icon: ['fas', 'wallet'],
                children: [
                    {
                        index: "/mall/user_center/account/personal",
                        label: "个人账户",
                        icon: ['fas', 'money-check'],
                    },
                    {
                        index: "/mall/user_center/account/store",
                        label: "商店账户",
                        icon: ['fas', 'coins'],
                    },
                    {
                        index: "/mall/user_center/account/recharge",
                        label: "账户充值",
                        icon: ['fas', 'money-bill-transfer'],
                    },
                ],
            },
        ],

        // 普通用户用户中心侧边栏
        normalUserCenterMenu: [
            {
                index: "/mall/user_center/userinfo",
                label: "个人信息",
                icon: ['fas', 'user'],
            },
            {
                index: "/mall/user_center/address",
                label: "收货地址",
                icon: ['fas', 'map-location'],
            },
            {
                index: "/mall/user_center/revoke",
                label: "退款申请",
                icon: ['fas', 'handshake-slash']
            },
            {
                label: "我的订单",
                name: 'my-orders',
                icon: ['fas', 'clipboard-list'],
                children: [
                    {
                        index: "/mall/user_center/order/all",
                        label: "所有订单",
                        icon: ['fas', 'receipt'],
                    },
                    {
                        index: "/mall/user_center/order/pay",
                        label: "待付款",
                        icon: ['fas', 'credit-card'],
                    },
                    {
                        index: "/mall/user_center/order/send",
                        label: "待发货",
                        icon: ['fas', 'box'],
                    },
                    {
                        index: "/mall/user_center/order/receive",
                        label: "待收货",
                        icon: ['fas', 'truck-fast'],
                    },
                    {
                        index: "/mall/user_center/order/finish",
                        label: "已完成",
                        icon: ['fas', 'comment-dots'],
                    },
                    {
                        index: "/mall/user_center/order/revoke",
                        label: "已撤销",
                        icon: ['fas', 'reply'],
                    },
                    {
                        index: "/mall/user_center/order/refund",
                        label: "已退款",
                        icon: ['fas', 'hand-holding-dollar'],
                    }
                ],
            },
            {
                label: "我的账户",
                name: 'my-account',
                icon: ['fas', 'wallet'],
                children: [
                    {
                        index: "/mall/user_center/account/personal",
                        label: "个人账户",
                        icon: ['fas', 'money-check'],
                    },
                    {
                        index: "/mall/user_center/account/recharge",
                        label: "账户充值",
                        icon: ['fas', 'money-bill-transfer'],
                    },
                ],
            },
        ],
    },
    mutations: {
        updateIsCollapse(state, payload) {
            state.isCollapse = !state.isCollapse;
        },

        updateMallMainScrollBarRef(state, val) {
            state.MallMainScrollBarRef = val;
        }
    },
    modules: {
        user,
        store,
        commodity,
        order,
        address,
        activity,
    },
    plugins: [
        // 使用sessionStorage实现持久化
        createPersistedState({
            storage: window.sessionStorage,
        })
    ]
})